package com.zxl.permission.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.apache.tomcat.util.codec.binary.Base64;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class TokenGenerater {
    private static final long EXPIRE_DATE = 30 * 60 * 100000;
    private static final String TOKEN_SECRET = "EQW6Q03EFJJX02X8AXB2HAD";   //token秘钥
    private static final Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);


    public static String encrypt(String data) {
        long timestamp = System.currentTimeMillis();
        String token = JWT.create()
                .withClaim("data", data)
                .withClaim("timestamp", timestamp)
                .sign(algorithm);
        return token.substring(0, 32) + token.substring(48, 80);

    }
}
